import { EnrollBookState, rfidModel } from '@/pages/enrollBook/interface';
import request from './index';
export function fetchEnrollBookList(params: {
    pageSize: number;
    current: number;
    rfid?: string;
    isbn?: string;
    book_name?: string;
    author?: string;
    cate_name?: string;
    publishing_house?: string;
    publish_date?: number;
    img_url?: string;
}): Promise<RDD<{ total: number; data: EnrollBookState[] }>> {
    return request.post('/getBookList', {
        data: {
            status: 1,
            ...params,
        },
    });
}
export function fetchBookTypeList(): Promise<RD> {
    return request.post('/getCateInfo', {
        params: {
            encode: true,
        },
    });
}
export function addBook(data: EnrollBookState): Promise<RD> {
    return request.post('/bookAdd', {
        data: data,
    });
}
export function batchAddBook(data: { bookInfo: string }): Promise<RD> {
    return request.post('/bookBatchAdd', {
        data: {
            bookInfo: data.bookInfo,
        },
    });
}
export function modifyBook(data: EnrollBookState): Promise<RD> {
    return request.post('/bookEdit', {
        data: data,
    });
}
export function batchModifyBook(data: { bookInfo: string }): Promise<RD> {
    return request.post('/bookBatchEdit', {
        data: {
            bookInfo: data.bookInfo,
        },
    });
}
export function fetchBookDetails(
    id: string | string[],
): Promise<RDD<{ data: EnrollBookState[] | EnrollBookState }>> {
    const data = Array.isArray(id)
        ? { book_ids: JSON.stringify(id) }
        : { book_id: id };
    return request.post('/getBookDetail', {
        data: data,
    });
}
export function deleteBook(data: { book_id: string }): Promise<RD> {
    return request.post('/bookDelete', {
        data: {
            book_id: data.book_id,
        },
    });
}
export function batchDeleteBook(data: { book_ids: [string] }): Promise<RD> {
    return request.post('/bookBatchDelete', {
        data: {
            book_ids: data.book_ids,
        },
    });
}

export function getScannerInfo(data: {
    test: string;
}): Promise<RDD<EnrollBookState>> {
    return request.post('/getScannerInfo', {
        data: {
            test: data.test,
        },
    });
}

export function getScannerInfoForIsbn(data: {
    isbn: string;
}): Promise<RDD<EnrollBookState>> {
    return request.post('/searchBook', {
        data: {
            isbn: data.isbn,
        },
    });
}

export function getScannerInfoForRfid(data: {
    test: string;
}): Promise<RDD<rfidModel>> {
    return request.post('/getScannerRfid', {
        data: {
            test: data.test,
        },
    });
}
